#include "Stack.h"

void STInit(ST* st)
{
	assert(st);
	StackDataType* ret = (StackDataType*)calloc(MAX, sizeof(StackDataType));
	if (!ret)
	{
		perror("colloc");
		return;
	}
	st->a = ret;
	st->capacity = MAX;
	st->top = 0;
	ret = NULL;
}
void STDestroy(ST* st)
{
	assert(st);
	free(st->a);
	st->capacity = 0;
	st->top = 0;

}
void STPush(ST* st, int x)
{
	assert(st);
	if (st->top == st->capacity)
	{
		StackDataType* ret = (StackDataType*)realloc(st->a,st->capacity*DOU*sizeof(StackDataType));
		if (!ret)
		{
			perror("colloc");
			return;
		}
		st->a = ret;
		st->capacity *= DOU;
		ret = NULL;
	}
	st->a[st->top++] = x;
	
}
void STPop(ST* st)
{
	assert(st);
	if (STEmpty(st))
	{
		return;
	}

	st->top--;

}
StackDataType STTop(ST* st)
{
	assert(st);
	if (STEmpty(st))
	{
		return NULL;
	}
	return st->a[st->top - 1];
}
bool STEmpty(ST* st)
{
	assert(st);
	return st->top == 0;
}
int STSize(ST* st)
{
	assert(st);
	assert(st->top >= 0);
	return st->top;
}
